package com.hanhanxiaochong.zhongxiangchuanmei.view.shop.adapter;

import android.content.Context;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.CouponBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.CommonAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ViewHolder;
import com.hanhanxiaochong.zhongxiangchuanmei.util.ResourcesUtils;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.utils.TimeUtils;

import java.util.List;

/**
 * Created by RockPhoenix on 2018/5/30.
 */

public class CouponAdapter extends CommonAdapter<CouponBean> {

    public CouponAdapter(Context context, int layoutId, List<CouponBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, CouponBean bean, int position) {
        TextView money = holder.getView(R.id.tv_coupon_money);
        TextView name = holder.getView(R.id.tv_coupon_name);
        TextView time = holder.getView(R.id.tv_coupon_time);
        String d_discount = bean.getD_discount();
        if (d_discount.equals("0")) {
            money.setText("免费");
        } else {
            money.setText(String.format(ResourcesUtils.getString(R.string.good_price), d_discount));
        }
        name.setText(bean.getC_name());
        time.setText(String.format(ResourcesUtils.getString(R.string.term), TimeUtils.getDateFromSeconds(bean.getEffective_time())));
        holder.itemView.setOnClickListener(v -> mOnItemClickListener.onItemClick(this, position));
    }
}
